<?php

use \cass\Data,
 Doctrine\Common\ClassLoader,
 Doctrine\ORM\Configuration,
 Doctrine\ORM\EntityManager,
 Doctrine\Commonn\Cache\ApcCache;

define('__PATH__', realpath('../../../'));
require_once __PATH__ . '/lib/cass/abstract/Element.class.php';
require_once __PATH__ . '/lib/cass/Data.class.php';
require_once __PATH__ . Data::directories('doctrine') . '/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';

// Set up class loading. You could use different autoloaders, provided by your favorite framework,
// if you want to.
$classLoader = new ClassLoader('Doctrine\ORM', __PATH__ . Data::directories('doctrine'));
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\DBAL', __PATH__ . Data::directories('doctrine') . '/vendor/doctrine-dbal/lib');
$classLoader->register();
$classLoader = new ClassLoader('Doctrine\Common', __PATH__ . Data::directories('doctrine') . '/vendor/doctrine-common/lib');
$classLoader->register();
$classLoader = new ClassLoader('Symfony', __PATH__ . Data::directories('doctrine') . '/vendor');
$classLoader->register();
$classLoader = new ClassLoader(null, __PATH__ . Data::directories('doctrine') . '/config/Entities/');
$classLoader->register();
$classLoader = new ClassLoader(null, __PATH__ . Data::directories('doctrine') . 'config/Repositories/');
$classLoader->register();
$classLoader = new ClassLoader('Proxies', __PATH__ . Data::directories('doctrine') . '/config/Proxies/');
$classLoader->register();


$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = new Doctrine\ORM\Mapping\Driver\YamlDriver(__PATH__ . Data::directories('doctrine') . '/config/yaml/');
//$driverImpl = $config->newDefaultAnnotationDriver(array(__PATH__ .  Data::directories('doctrine') . '/config/Entities'));
$config->setMetadataDriverImpl($driverImpl);

$config->setProxyDir(__PATH__ . Data::directories('doctrine') . '/config/Proxies/');
$config->setProxyNamespace('Proxies');

$connectionOptions = array(
    'driver' => 'pdo_mysql',
    'host' => Data::database('host'),
    'dbname' => Data::database('dbname'),
    'user' => Data::database('user'),
    'password' => Data::database('password')
);

$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

$helpers = array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
);